class Solution {
    public int[] searchRange(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int[] arr = new int[]{-1,-1};
        //nums为空数组
        if (nums.length == 0) return arr;
        //查找左边界
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] < target) {
                left = mid + 1;
            }else {
                right = mid;
            }
        }
        //数组中不存在target
        if (nums[left] != target) return arr;
        arr[0] = left;
        left = 0;
        right = nums.length - 1;
        //查找右边界
        while (left < right) {
            int mid = left + (right - left + 1) / 2;
            if (nums[mid] <= target) {
                left = mid;
            }else {
                right = mid - 1;
            }
        }
        arr[1] = left;
        return arr;
    }
}